import itertools
import math


# 先计算一下可能出现的各个位数的长度，这里假设len(multiplicand) <= len(multiplier)
# lenth = []
# for i in range(1, 10):
#     for j in range(i, 10):
#         if 2 * (i + j) >= 9 and i + j <= 5:
#             lenth.append([i, j, 9 - i - j])
# print(lenth)


def get_sum_part(num_str):
    poss_len_part = [[1, 4, 4], [2, 3, 4]]
    res = []
    for index in poss_len_part:
        if int(''.join(num_str[:index[0]])) * int(''.join(num_str[index[0]:index[0] + index[1]])) == int(
                ''.join(num_str[index[0] + index[1]:index[0] + index[1] + index[2]])):
            print(num_str, index)
            res.append(int(''.join(num_str[index[0] + index[1]:index[0] + index[1] + index[2]])))
    return res


if __name__ == '__main__':
    nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
    fin_res = []
    for i in itertools.permutations(nums, 9):
        fin_res.extend(get_sum_part(''.join(i)))
    print('===========')
    print(sum(set(fin_res)))
